import cv2

if __name__ == '__main__':
    img0 = cv2.imread("../template/system.JPG", cv2.IMREAD_GRAYSCALE)
    img1_original = cv2.imread(R"F:\Project\DeepLearning\Game\MHXY\material\1710771893.6206677.jpg")
    img1 = cv2.cvtColor(img1_original, cv2.COLOR_BGR2GRAY)
    r = cv2.matchTemplate(img1, img0, cv2.TM_CCOEFF_NORMED)
    (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(r)
    # 匹配度在95%以上时,认为找到目标
    if maxVal > 0.95:
        # 确定起点和终点的（x，y）坐标边界框
        (startX, startY) = maxLoc
        endX = startX + img0.shape[1]
        endY = startY + img0.shape[0]
        # 在图像上绘制边框
        cv2.rectangle(img1_original, (startX, startY), (endX, endY), (0, 0, 255), 3)
        # 缩放
        imgResult = cv2.resize(img1_original, (0, 0), fx=0.3, fy=0.3)
        # 显示输出图像
        cv2.imshow("Output", imgResult)
        cv2.waitKey(0)
